home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / midi / midifile.lha / Midifile / mfwrite_ex.c < prev    next >
C/C++ Source or Header  |  1995-08-13  |  1KB  |  59 lines

  1. /*
  2.  * writing_example.c 4/30/89
  3.  *
  4.  */
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "midifile.h"
  8.  
  9. /* These lines are needed to use the library */
  10. FILE *fp;
  11. myputc (c)
  12. {
  13.   return (putc (c, fp));
  14. }
  15.  
  16.  
  17. /*
  18.  * mywritetrack()
  19.  *
  20.  * Sample showing how to use the library routines to write out a track.
  21.  * Returns 1 if successful, and -1 if not.  The track consists of
  22.  * a series of quarter notes from lowest to highest in pitch at
  23.  * constant velocity, each separted by a quarter-note rest.
  24.  *
  25.  */
  26. int 
  27. mywritetrack (track)
  28.      int track;
  29. {
  30.   int i;
  31.   char data[2];
  32.  
  33.   mf_write_tempo ((long) 500000);    /* 120 beats/per/second */
  34.  
  35.   for (i = 1; i < 128; i++)
  36.     {
  37.       data[0] = i;        /* note number */
  38.       data[1] = 64;        /* velocity */
  39.       if (!mf_write_midi_event (480, note_on, 1, data, 2))
  40.     return (-1);
  41.       if (!mf_write_midi_event (480, note_off, 1, data, 2))
  42.     return (-1);
  43.     }
  44.   return (1);
  45. }                /* end of write_track() */
  46.  
  47. main (argc, argv)
  48.      char **argv;
  49. {
  50.   if ((fp = fopen (argv[1], "w")) == 0L)
  51.     printf ("f1to0: unable to open file %s for writing.\n", argv[1]);
  52.  
  53.   Mf_putc = myputc;
  54.   Mf_writetrack = mywritetrack;
  55.  
  56.   /* write a single track */
  57.   mfwrite (0, 1, 480, fp);
  58. }
  59.